package com.zhouchj.elasticsearch.basic;


import cn.hutool.core.text.CharSequenceUtil;
import com.google.gson.FieldNamingStrategy;

import java.lang.reflect.Field;

/**
 * ES字段命名策略
 *
 * @author zhouchj
 * @date 2023/8/24
 */
public class EsFieldNamingPolicy implements FieldNamingStrategy {
    /**
     * Translates the field name into its JSON field name representation.
     *
     * @param field the field object that we are translating
     * @return the translated field name.
     * @since 1.3
     */
    @Override
    public String translateName(Field field) {
        if (field.isAnnotationPresent(org.springframework.data.elasticsearch.annotations.Field.class)) {
            return field.getAnnotation(org.springframework.data.elasticsearch.annotations.Field.class).name();
        }
        return CharSequenceUtil.toUnderlineCase(field.getName());
    }
}
